<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        
        echo $this->view->util()->registerScriptJSController($this->getRequest());
		
		$pdataUser = new Zend_Session_Namespace('UserLog');
		//$pdataUser->setExpirationSeconds(1);

		if( !isset($pdataUser->Pcoduser) ){
				echo '<script type="text/javascript">$(document).ready(function(){$("#dialog-login").dialog("open");});</script>';
		}
		echo "Bienvenido ".$pdataUser->Pnombreuser;
		 
    }
	public function valuserAction(){
		
		$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		
		if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();
			
			$puser = $this->_request->getPost('puser');
			$ppasswd = $this->_request->getPost('ppasswd');
			
			$cn = new Model_Data();
			$parameter[]=array("@puser",$puser);
			$parameter[]=array("@ppasswd",$ppasswd);
			$result = $cn ->ejec_store_procedura_sql("Musuarios_Validar", $parameter);
			if (!count($result)==0 ){
				$pdataUser = new Zend_Session_Namespace('UserLog');
				$pdataUser->Pcoduser = $result[0][0];
				$pdataUser->Pnombreuser = $result[0][1];
				$pdataUser->Pcodperson = $result[0][4];
				$pdataUser->Puser = $puser;
				$pdataUser->Ppwd = $ppasswd;
				echo '<script type="text/javascript">$(document).ready(function(){document.location.href =jQuery.scriptPath;});</script>';
			}
		}

	}
	public function logoutAction(){
		
		
		$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();	
			Zend_Session::namespaceUnset('UserLog');
		}
	}


}

